package com.camera2.activity;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

import com.camera2.view.BottomBar;


public class Frament extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frament);

        BottomBar bottomBar = findViewById(R.id.bottom_bar);
        bottomBar.setContainer(R.id.fl_container)
                .setTitleBeforeAndAfterColor("#999999", "#228b22")
                .addItem(FramentHome.class,
                        "首页",
                        R.drawable.home1,
                        R.drawable.home2)
                .addItem(FramentTake.class,
                        "识伤",
                        R.drawable.take1,
                        R.drawable.take2)
                .addItem(FramentMy.class,
                        "我的",
                        R.drawable.my1,
                        R.drawable.my2)
                .build();
        checkGps();
    }

    private void checkGps() {
        String[] permissions = new String[]{
                Manifest.permission.WRITE_EXTERNAL_STORAGE,
                Manifest.permission.CAMERA};

        boolean c3 = checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE);
        boolean c4 = checkPermission(Manifest.permission.CAMERA);
        if (c3 && c4) {
//            if (!username.equals("") && !password.equals("")) {
//                login();
//            }
        } else {
            getPermission(Manifest.permission.READ_EXTERNAL_STORAGE, permissions);
        }
    }

    public boolean checkPermission(String permission) {
        if (ActivityCompat.checkSelfPermission(this, permission)
                == PackageManager.PERMISSION_GRANTED)
            return true;
        else
            return false;
    }

    public void getPermission(String permission, String[] permissions) {
        ActivityCompat.requestPermissions(this, permissions, 1);
        if (ActivityCompat.shouldShowRequestPermissionRationale(this, permission))
            Toast.makeText(this, "请开通相关权限，否则无法正常使用本应用！", Toast.LENGTH_SHORT).show();

    }
}
